﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using LevenBlog.Core.Data;
using LevenBlog.Core.Entities;

namespace LevenBlog.Data.SqlServer
{
    public sealed class SqlState : IState
    {
        public void Inser(IDbProvider provider, lb_state state)
        {
            IDataParameter[] paras = null;
            string sql = SqlHelper.Instance.CreateInsertSql(state, out paras);
            SqlHelper.Instance.ExecuteNonQuery(provider, sql, paras);
        }

        public void Update(IDbProvider provider, lb_state state)
        {
            IDataParameter[] paras = null;
            string sql = SqlHelper.Instance.CreateUpdateSql(state, out paras);
            SqlHelper.Instance.ExecuteNonQuery(provider, sql, paras);
        }

        public lb_state Get(IDbProvider provider)
        {
            string sql = "select top 1 * from [lb_state] order by [id] asc";
            using (IDataReader dr = SqlHelper.Instance.ExecuteDataReader(provider, sql))
            {
                return SqlHelper.Instance.ConvertToEntity<lb_state>(dr);
            }
        }
    }
}
